package com.jgp.sys.query;


import com.jgp.common.persistence.Model;

import java.util.Objects;
import java.util.stream.Collectors;

/**
 * 项目   jgp
 * 作者   loufei
 * 时间   2017/10/19
 */
public class Join {
    private String leftField;
    private Class<? extends Model> joinClass;
    private String joinField;
    private JoinDirection joinDirection;
    private QueryFilterList joinFilters;
    private OrderList joinOrders;

    /**
     * 构造Join查询
     * @param leftField
     * @param joinClass
     * @param joinDirection
     * @param joinField
     */
    public Join(String leftField, Class<? extends Model> joinClass, JoinDirection joinDirection, String
            joinField) {
        this.leftField = leftField;
        this.joinClass = joinClass;
        this.joinDirection = joinDirection;
        this.joinField = joinField;
    }

    public String getLeftField() {
        return leftField;
    }

    public Class<? extends Model> getJoinClass() {
        return joinClass;
    }

    public JoinDirection getJoinDirection() {
        return joinDirection;
    }

    public String getJoinField() {
        return joinField;
    }

    public Join setJoinFilters(QueryFilterList joinFilters) {
        QueryFilterList filters = new QueryFilterList();
        filters.addFilters(joinFilters.stream().filter(filter -> Objects.nonNull(filter.getOperator())).collect(Collectors.toList()));
        this.joinFilters = filters;
        return this;
    }
    
    public QueryFilterList getJoinFilters() {
        return joinFilters;
    }
    
    public OrderList getJoinOrders() {
        return joinOrders;
    }
    
    public Join setJoinOrders(OrderList joinOrders) {
        this.joinOrders = joinOrders;
        return this;
    }
}
